package com.apes;

import com.apes.framework.jpa.repository.ExtendedJpaRepository;
import com.apes.framework.util.SystemUtil;
import com.apes.framework.util.bean.compiler.ApesClassLoaderImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationListener;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableTransactionManagement
@EnableCaching
@EnableJpaRepositories(repositoryBaseClass = ExtendedJpaRepository.class)
public class ApesPiApplication {

    public static void main(String[] args) {
        SystemUtil.setProperties();
        SpringApplication application = new SpringApplication(ApesPiApplication.class);
        application.addListeners((ApplicationListener<ApplicationStartingEvent>) event -> {
            ClassLoader classLoader = new ApesClassLoaderImpl(Thread.currentThread().getContextClassLoader());
            Thread.currentThread().setContextClassLoader(classLoader);
        });
        application.run(args);
    }

}
